package com.joinway.framework.support.session;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.joinway.framework.core.utils.FrameworkHelper;

public class HttpSessionModel implements ISessionModel {

	private static final Logger log = LoggerFactory.getLogger(HttpSessionModel.class);

	@Override
	public <T> T get(String key, Class<T> type) {
		HttpSession session = FrameworkHelper.getHttpServletRequest().getSession();
		@SuppressWarnings("unchecked")
		T value = (T) session.getAttribute(key);
		
		return value;
	}

	@Override
	public void set(String key, Object value) {
		HttpSession session = FrameworkHelper.getHttpServletRequest().getSession();
		session.setAttribute(key, value);
	}

	@Override
	public void remove(String key) {
		HttpSession session = FrameworkHelper.getHttpServletRequest().getSession();
		session.removeAttribute(key);
	}

	@Override
	public String getId() {
		HttpSession session = FrameworkHelper.getHttpServletRequest().getSession();
		return session.getId();
	}

	@Override
	public void invalidate() {
		HttpSession session = FrameworkHelper.getHttpServletRequest().getSession();
		session.invalidate();
	}
}

